package com.woniuxy.service.impl;

import com.woniuxy.dao.IProductDao;
import com.woniuxy.domain.Product;
import com.woniuxy.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@Transactional
public class ProductServiceImpl implements IProductService {
    @Autowired
    private IProductDao iProductDao;

    @Override
    public Product getProductById(Integer id) {
        Optional<Product> optional = iProductDao.findById(id);
        Product product = null;
        if (optional.isPresent()) {
            product = optional.get();
        }
        return product;
    }



    @Override
    public void addProduct(Product product) {
        if (!product.getPname().contains("备用")) {
            iProductDao.save(product);
        }
    }

}
